package com.msp.ws.impl;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.xml.ws.WebServiceContext;

import com.msp.ws.IDreamWS;

@WebService(serviceName="DreamWSImplService")
@SOAPBinding(style = Style.RPC)
public class DreamWSImpl implements IDreamWS{
	@Resource
	private WebServiceContext context;

	@WebMethod
	public void test() {
		// TODO Auto-generated method stub
		
	} 

//	@WebMethod
//	public String getAllPictures() {
//		ServletContext servletContext = (ServletContext) context
//		    .getMessageContext().get("javax.xml.ws.servlet.context");
//		WebApplicationContext webApplicationContext = WebApplicationContextUtils
//		    .getRequiredWebApplicationContext(servletContext);
//		IPictureService pictureService = (IPictureService) webApplicationContext
//			    .getAutowireCapableBeanFactory().getBean("pictureService");
//		List<Picture> pictures = (List<Picture>)pictureService.getAllPictures();
//		Type type = new TypeToken<List<Picture>>(){}.getType();
//		String resultString = new Gson().toJson(pictures, type);
//		return resultString;
//	}
//	
//	@WebMethod
//	public String getAllPicIds() {
//		ServletContext servletContext = (ServletContext) context
//		    .getMessageContext().get("javax.xml.ws.servlet.context");
//		WebApplicationContext webApplicationContext = WebApplicationContextUtils
//		    .getRequiredWebApplicationContext(servletContext);
//		IPictureService pictureService = (IPictureService) webApplicationContext
//			    .getAutowireCapableBeanFactory().getBean("pictureService");
//		List<Picture> pictures = (List<Picture>)pictureService.getAllPictures();
//		List<Integer> picIds = new ArrayList<Integer>();
//		for (Picture pciture : pictures) {
//			picIds.add(pciture.getId());
//		}
//		Type type = new TypeToken<List<Integer>>(){}.getType();
//		String resultString = new Gson().toJson(picIds, type);
//		return resultString;
//	}
//
//	@WebMethod
//	public String getPictureById(@WebParam(name="picId")Integer picId) {
//		ServletContext servletContext = (ServletContext) context
//		    .getMessageContext().get("javax.xml.ws.servlet.context");
//		WebApplicationContext webApplicationContext = WebApplicationContextUtils
//		    .getRequiredWebApplicationContext(servletContext);
//		IPictureService pictureService = (IPictureService) webApplicationContext
//			    .getAutowireCapableBeanFactory().getBean("pictureService");
//		Type type = new TypeToken<Picture>(){}.getType();
//		Picture picture = pictureService.getPictureById(picId);
//		String resultString = new Gson().toJson(picture, type);
//		return resultString;
//	}
//
//	@WebMethod
//	public Integer saveDeviceInfoWhenOnline(@WebParam(name="deviceNo")String deviceNo, @WebParam(name="deviceName")String deviceName) {
//		ServletContext servletContext = (ServletContext) context
//		    .getMessageContext().get("javax.xml.ws.servlet.context");
//		WebApplicationContext webApplicationContext = WebApplicationContextUtils
//		    .getRequiredWebApplicationContext(servletContext);
//		IDeviceService deviceService = (IDeviceService) webApplicationContext
//				.getAutowireCapableBeanFactory().getBean("deviceService");
//		Integer deviceDetailId = deviceService.saveDeviceInfoWhenOnline(deviceNo, deviceName);
//		return deviceDetailId;
//	}
//
//	@WebMethod
//	public void updateDeviceDetailWhenOffline(@WebParam(name="deviceDetailId")Integer deviceDetailId) {
//		ServletContext servletContext = (ServletContext) context
//		    .getMessageContext().get("javax.xml.ws.servlet.context");
//		WebApplicationContext webApplicationContext = WebApplicationContextUtils
//		    .getRequiredWebApplicationContext(servletContext);
//		IDeviceService deviceService = (IDeviceService) webApplicationContext
//				.getAutowireCapableBeanFactory().getBean("deviceService");
//		deviceService.updateDeviceDetailWhenOffline(deviceDetailId);
//		
//	}
}
